// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <PyPlot.h>
#include <ObserverToCallback.h>
#include <stdio.h>
#include <Py2and3Support.h>

// ****************************************************************************
// Module: PyPlot
//
// Purpose:
//   This class is a plot element in a plot list.
//
// Note:       Autogenerated by xml2python. Do not modify by hand!
//
// Programmer: xml2python
// Creation:   omitted
//
// ****************************************************************************

//
// This struct contains the Python type information and a Plot.
//
struct PlotObject
{
    PyObject_HEAD
    Plot *data;
    bool        owns;
    PyObject   *parent;
};

//
// Internal prototypes
//
static PyObject *NewPlot(int);
std::string
PyPlot_ToString(const Plot *atts, const char *prefix, const bool forLogging)
{
    std::string str;
    char tmpStr[1000];

    const char *stateType_names = "NewlyCreated, Pending, Completed, Error";
    switch (atts->GetStateType())
    {
      case Plot::NewlyCreated:
          snprintf(tmpStr, 1000, "%sstateType = %sNewlyCreated  # %s\n", prefix, prefix, stateType_names);
          str += tmpStr;
          break;
      case Plot::Pending:
          snprintf(tmpStr, 1000, "%sstateType = %sPending  # %s\n", prefix, prefix, stateType_names);
          str += tmpStr;
          break;
      case Plot::Completed:
          snprintf(tmpStr, 1000, "%sstateType = %sCompleted  # %s\n", prefix, prefix, stateType_names);
          str += tmpStr;
          break;
      case Plot::Error:
          snprintf(tmpStr, 1000, "%sstateType = %sError  # %s\n", prefix, prefix, stateType_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    snprintf(tmpStr, 1000, "%splotType = %d\n", prefix, atts->GetPlotType());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%splotName = \"%s\"\n", prefix, atts->GetPlotName().c_str());
    str += tmpStr;
    if(atts->GetActiveFlag())
        snprintf(tmpStr, 1000, "%sactiveFlag = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%sactiveFlag = 0\n", prefix);
    str += tmpStr;
    if(atts->GetHiddenFlag())
        snprintf(tmpStr, 1000, "%shiddenFlag = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%shiddenFlag = 0\n", prefix);
    str += tmpStr;
    if(atts->GetExpandedFlag())
        snprintf(tmpStr, 1000, "%sexpandedFlag = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%sexpandedFlag = 0\n", prefix);
    str += tmpStr;
    snprintf(tmpStr, 1000, "%splotVar = \"%s\"\n", prefix, atts->GetPlotVar().c_str());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sdatabaseName = \"%s\"\n", prefix, atts->GetDatabaseName().c_str());
    str += tmpStr;
    {   const intVector &operators = atts->GetOperators();
        snprintf(tmpStr, 1000, "%soperators = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < operators.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%d", operators[i]);
            str += tmpStr;
            if(i < operators.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const stringVector &operatorNames = atts->GetOperatorNames();
        snprintf(tmpStr, 1000, "%soperatorNames = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < operatorNames.size(); ++i)
        {
            snprintf(tmpStr, 1000, "\"%s\"", operatorNames[i].c_str());
            str += tmpStr;
            if(i < operatorNames.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    snprintf(tmpStr, 1000, "%sactiveOperator = %d\n", prefix, atts->GetActiveOperator());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sid = %d\n", prefix, atts->GetId());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sembeddedPlotId = %d\n", prefix, atts->GetEmbeddedPlotId());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sbeginFrame = %d\n", prefix, atts->GetBeginFrame());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sendFrame = %d\n", prefix, atts->GetEndFrame());
    str += tmpStr;
    {   const intVector &keyframes = atts->GetKeyframes();
        snprintf(tmpStr, 1000, "%skeyframes = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < keyframes.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%d", keyframes[i]);
            str += tmpStr;
            if(i < keyframes.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const intVector &numKeyframesPerOperator = atts->GetNumKeyframesPerOperator();
        snprintf(tmpStr, 1000, "%snumKeyframesPerOperator = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < numKeyframesPerOperator.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%d", numKeyframesPerOperator[i]);
            str += tmpStr;
            if(i < numKeyframesPerOperator.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const intVector &operatorKeyframes = atts->GetOperatorKeyframes();
        snprintf(tmpStr, 1000, "%soperatorKeyframes = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < operatorKeyframes.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%d", operatorKeyframes[i]);
            str += tmpStr;
            if(i < operatorKeyframes.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const intVector &databaseKeyframes = atts->GetDatabaseKeyframes();
        snprintf(tmpStr, 1000, "%sdatabaseKeyframes = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < databaseKeyframes.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%d", databaseKeyframes[i]);
            str += tmpStr;
            if(i < databaseKeyframes.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    if(atts->GetIsFromSimulation())
        snprintf(tmpStr, 1000, "%sisFromSimulation = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%sisFromSimulation = 0\n", prefix);
    str += tmpStr;
    if(atts->GetFollowsTime())
        snprintf(tmpStr, 1000, "%sfollowsTime = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%sfollowsTime = 0\n", prefix);
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sdescription = \"%s\"\n", prefix, atts->GetDescription().c_str());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sselection = \"%s\"\n", prefix, atts->GetSelection().c_str());
    str += tmpStr;
    if(atts->GetAnimatingFlag())
        snprintf(tmpStr, 1000, "%sanimatingFlag = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%sanimatingFlag = 0\n", prefix);
    str += tmpStr;
    return str;
}

static PyObject *
Plot_Notify(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;
    obj->data->Notify();
    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
Plot_SetStateType(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 4)
    {
        std::stringstream ss;
        ss << "An invalid stateType value was given." << std::endl;
        ss << "Valid values are in the range [0,3]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " NewlyCreated";
        ss << ", Pending";
        ss << ", Completed";
        ss << ", Error";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the stateType in the object.
    obj->data->SetStateType(Plot::StateType(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
Plot_GetStateType(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetStateType()));
    return retval;
}

/*static*/ PyObject *
Plot_SetPlotType(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the plotType in the object.
    obj->data->SetPlotType(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
Plot_GetPlotType(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetPlotType()));
    return retval;
}

/*static*/ PyObject *
Plot_SetPlotName(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the plotName in the object.
    obj->data->SetPlotName(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
Plot_GetPlotName(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetPlotName().c_str());
    return retval;
}

/*static*/ PyObject *
Plot_SetActiveFlag(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the activeFlag in the object.
    obj->data->SetActiveFlag(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
Plot_GetActiveFlag(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetActiveFlag()?1L:0L);
    return retval;
}

/*static*/ PyObject *
Plot_SetHiddenFlag(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the hiddenFlag in the object.
    obj->data->SetHiddenFlag(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
Plot_GetHiddenFlag(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetHiddenFlag()?1L:0L);
    return retval;
}

/*static*/ PyObject *
Plot_SetExpandedFlag(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the expandedFlag in the object.
    obj->data->SetExpandedFlag(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
Plot_GetExpandedFlag(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetExpandedFlag()?1L:0L);
    return retval;
}

/*static*/ PyObject *
Plot_SetPlotVar(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the plotVar in the object.
    obj->data->SetPlotVar(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
Plot_GetPlotVar(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetPlotVar().c_str());
    return retval;
}

/*static*/ PyObject *
Plot_SetDatabaseName(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the databaseName in the object.
    obj->data->SetDatabaseName(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
Plot_GetDatabaseName(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetDatabaseName().c_str());
    return retval;
}

/*static*/ PyObject *
Plot_SetOperators(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;

    intVector vec;

    if (PyNumber_Check(args))
    {
        long val = PyLong_AsLong(args);
        int cval = int(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ int");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ int");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            long val = PyLong_AsLong(item);
            int cval = int(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ int", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ int", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more ints");

    obj->data->GetOperators() = vec;
    // Mark the operators in the object as modified.
    obj->data->SelectOperators();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
Plot_GetOperators(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;
    // Allocate a tuple the with enough entries to hold the operators.
    const intVector &operators = obj->data->GetOperators();
    PyObject *retval = PyTuple_New(operators.size());
    for(size_t i = 0; i < operators.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyInt_FromLong(long(operators[i])));
    return retval;
}

/*static*/ PyObject *
Plot_SetOperatorNames(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;

    stringVector vec;

    if (PyUnicode_Check(args))
    {
        char const *val = PyUnicode_AsUTF8(args);
        std::string cval = std::string(val);
        if (val == 0 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ string");
        }
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyUnicode_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a unicode string", (int) i);
            }

            char const *val = PyUnicode_AsUTF8(item);
            std::string cval = std::string(val);

            if (val == 0 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ string", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more string(s)");

    obj->data->GetOperatorNames() = vec;
    // Mark the operatorNames in the object as modified.
    obj->data->SelectOperatorNames();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
Plot_GetOperatorNames(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;
    // Allocate a tuple the with enough entries to hold the operatorNames.
    const stringVector &operatorNames = obj->data->GetOperatorNames();
    PyObject *retval = PyTuple_New(operatorNames.size());
    for(size_t i = 0; i < operatorNames.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyString_FromString(operatorNames[i].c_str()));
    return retval;
}

/*static*/ PyObject *
Plot_SetActiveOperator(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the activeOperator in the object.
    obj->data->SetActiveOperator(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
Plot_GetActiveOperator(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetActiveOperator()));
    return retval;
}

/*static*/ PyObject *
Plot_SetId(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the id in the object.
    obj->data->SetId(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
Plot_GetId(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetId()));
    return retval;
}

/*static*/ PyObject *
Plot_SetEmbeddedPlotId(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the embeddedPlotId in the object.
    obj->data->SetEmbeddedPlotId(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
Plot_GetEmbeddedPlotId(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetEmbeddedPlotId()));
    return retval;
}

/*static*/ PyObject *
Plot_SetBeginFrame(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the beginFrame in the object.
    obj->data->SetBeginFrame(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
Plot_GetBeginFrame(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetBeginFrame()));
    return retval;
}

/*static*/ PyObject *
Plot_SetEndFrame(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the endFrame in the object.
    obj->data->SetEndFrame(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
Plot_GetEndFrame(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetEndFrame()));
    return retval;
}

/*static*/ PyObject *
Plot_SetKeyframes(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;

    intVector vec;

    if (PyNumber_Check(args))
    {
        long val = PyLong_AsLong(args);
        int cval = int(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ int");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ int");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            long val = PyLong_AsLong(item);
            int cval = int(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ int", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ int", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more ints");

    obj->data->GetKeyframes() = vec;
    // Mark the keyframes in the object as modified.
    obj->data->SelectKeyframes();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
Plot_GetKeyframes(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;
    // Allocate a tuple the with enough entries to hold the keyframes.
    const intVector &keyframes = obj->data->GetKeyframes();
    PyObject *retval = PyTuple_New(keyframes.size());
    for(size_t i = 0; i < keyframes.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyInt_FromLong(long(keyframes[i])));
    return retval;
}

/*static*/ PyObject *
Plot_SetNumKeyframesPerOperator(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;

    intVector vec;

    if (PyNumber_Check(args))
    {
        long val = PyLong_AsLong(args);
        int cval = int(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ int");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ int");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            long val = PyLong_AsLong(item);
            int cval = int(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ int", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ int", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more ints");

    obj->data->GetNumKeyframesPerOperator() = vec;
    // Mark the numKeyframesPerOperator in the object as modified.
    obj->data->SelectNumKeyframesPerOperator();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
Plot_GetNumKeyframesPerOperator(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;
    // Allocate a tuple the with enough entries to hold the numKeyframesPerOperator.
    const intVector &numKeyframesPerOperator = obj->data->GetNumKeyframesPerOperator();
    PyObject *retval = PyTuple_New(numKeyframesPerOperator.size());
    for(size_t i = 0; i < numKeyframesPerOperator.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyInt_FromLong(long(numKeyframesPerOperator[i])));
    return retval;
}

/*static*/ PyObject *
Plot_SetOperatorKeyframes(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;

    intVector vec;

    if (PyNumber_Check(args))
    {
        long val = PyLong_AsLong(args);
        int cval = int(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ int");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ int");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            long val = PyLong_AsLong(item);
            int cval = int(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ int", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ int", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more ints");

    obj->data->GetOperatorKeyframes() = vec;
    // Mark the operatorKeyframes in the object as modified.
    obj->data->SelectOperatorKeyframes();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
Plot_GetOperatorKeyframes(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;
    // Allocate a tuple the with enough entries to hold the operatorKeyframes.
    const intVector &operatorKeyframes = obj->data->GetOperatorKeyframes();
    PyObject *retval = PyTuple_New(operatorKeyframes.size());
    for(size_t i = 0; i < operatorKeyframes.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyInt_FromLong(long(operatorKeyframes[i])));
    return retval;
}

/*static*/ PyObject *
Plot_SetDatabaseKeyframes(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;

    intVector vec;

    if (PyNumber_Check(args))
    {
        long val = PyLong_AsLong(args);
        int cval = int(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ int");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ int");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            long val = PyLong_AsLong(item);
            int cval = int(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ int", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ int", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more ints");

    obj->data->GetDatabaseKeyframes() = vec;
    // Mark the databaseKeyframes in the object as modified.
    obj->data->SelectDatabaseKeyframes();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
Plot_GetDatabaseKeyframes(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;
    // Allocate a tuple the with enough entries to hold the databaseKeyframes.
    const intVector &databaseKeyframes = obj->data->GetDatabaseKeyframes();
    PyObject *retval = PyTuple_New(databaseKeyframes.size());
    for(size_t i = 0; i < databaseKeyframes.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyInt_FromLong(long(databaseKeyframes[i])));
    return retval;
}

/*static*/ PyObject *
Plot_SetIsFromSimulation(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the isFromSimulation in the object.
    obj->data->SetIsFromSimulation(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
Plot_GetIsFromSimulation(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetIsFromSimulation()?1L:0L);
    return retval;
}

/*static*/ PyObject *
Plot_SetFollowsTime(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the followsTime in the object.
    obj->data->SetFollowsTime(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
Plot_GetFollowsTime(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetFollowsTime()?1L:0L);
    return retval;
}

/*static*/ PyObject *
Plot_SetDescription(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the description in the object.
    obj->data->SetDescription(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
Plot_GetDescription(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetDescription().c_str());
    return retval;
}

/*static*/ PyObject *
Plot_SetSelection(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the selection in the object.
    obj->data->SetSelection(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
Plot_GetSelection(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetSelection().c_str());
    return retval;
}

/*static*/ PyObject *
Plot_SetAnimatingFlag(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the animatingFlag in the object.
    obj->data->SetAnimatingFlag(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
Plot_GetAnimatingFlag(PyObject *self, PyObject *args)
{
    PlotObject *obj = (PlotObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetAnimatingFlag()?1L:0L);
    return retval;
}



PyMethodDef PyPlot_methods[PLOT_NMETH] = {
    {"Notify", Plot_Notify, METH_VARARGS},
    {"SetStateType", Plot_SetStateType, METH_VARARGS},
    {"GetStateType", Plot_GetStateType, METH_VARARGS},
    {"SetPlotType", Plot_SetPlotType, METH_VARARGS},
    {"GetPlotType", Plot_GetPlotType, METH_VARARGS},
    {"SetPlotName", Plot_SetPlotName, METH_VARARGS},
    {"GetPlotName", Plot_GetPlotName, METH_VARARGS},
    {"SetActiveFlag", Plot_SetActiveFlag, METH_VARARGS},
    {"GetActiveFlag", Plot_GetActiveFlag, METH_VARARGS},
    {"SetHiddenFlag", Plot_SetHiddenFlag, METH_VARARGS},
    {"GetHiddenFlag", Plot_GetHiddenFlag, METH_VARARGS},
    {"SetExpandedFlag", Plot_SetExpandedFlag, METH_VARARGS},
    {"GetExpandedFlag", Plot_GetExpandedFlag, METH_VARARGS},
    {"SetPlotVar", Plot_SetPlotVar, METH_VARARGS},
    {"GetPlotVar", Plot_GetPlotVar, METH_VARARGS},
    {"SetDatabaseName", Plot_SetDatabaseName, METH_VARARGS},
    {"GetDatabaseName", Plot_GetDatabaseName, METH_VARARGS},
    {"SetOperators", Plot_SetOperators, METH_VARARGS},
    {"GetOperators", Plot_GetOperators, METH_VARARGS},
    {"SetOperatorNames", Plot_SetOperatorNames, METH_VARARGS},
    {"GetOperatorNames", Plot_GetOperatorNames, METH_VARARGS},
    {"SetActiveOperator", Plot_SetActiveOperator, METH_VARARGS},
    {"GetActiveOperator", Plot_GetActiveOperator, METH_VARARGS},
    {"SetId", Plot_SetId, METH_VARARGS},
    {"GetId", Plot_GetId, METH_VARARGS},
    {"SetEmbeddedPlotId", Plot_SetEmbeddedPlotId, METH_VARARGS},
    {"GetEmbeddedPlotId", Plot_GetEmbeddedPlotId, METH_VARARGS},
    {"SetBeginFrame", Plot_SetBeginFrame, METH_VARARGS},
    {"GetBeginFrame", Plot_GetBeginFrame, METH_VARARGS},
    {"SetEndFrame", Plot_SetEndFrame, METH_VARARGS},
    {"GetEndFrame", Plot_GetEndFrame, METH_VARARGS},
    {"SetKeyframes", Plot_SetKeyframes, METH_VARARGS},
    {"GetKeyframes", Plot_GetKeyframes, METH_VARARGS},
    {"SetNumKeyframesPerOperator", Plot_SetNumKeyframesPerOperator, METH_VARARGS},
    {"GetNumKeyframesPerOperator", Plot_GetNumKeyframesPerOperator, METH_VARARGS},
    {"SetOperatorKeyframes", Plot_SetOperatorKeyframes, METH_VARARGS},
    {"GetOperatorKeyframes", Plot_GetOperatorKeyframes, METH_VARARGS},
    {"SetDatabaseKeyframes", Plot_SetDatabaseKeyframes, METH_VARARGS},
    {"GetDatabaseKeyframes", Plot_GetDatabaseKeyframes, METH_VARARGS},
    {"SetIsFromSimulation", Plot_SetIsFromSimulation, METH_VARARGS},
    {"GetIsFromSimulation", Plot_GetIsFromSimulation, METH_VARARGS},
    {"SetFollowsTime", Plot_SetFollowsTime, METH_VARARGS},
    {"GetFollowsTime", Plot_GetFollowsTime, METH_VARARGS},
    {"SetDescription", Plot_SetDescription, METH_VARARGS},
    {"GetDescription", Plot_GetDescription, METH_VARARGS},
    {"SetSelection", Plot_SetSelection, METH_VARARGS},
    {"GetSelection", Plot_GetSelection, METH_VARARGS},
    {"SetAnimatingFlag", Plot_SetAnimatingFlag, METH_VARARGS},
    {"GetAnimatingFlag", Plot_GetAnimatingFlag, METH_VARARGS},
    {NULL, NULL}
};

//
// Type functions
//

static void
Plot_dealloc(PyObject *v)
{
   PlotObject *obj = (PlotObject *)v;
   if(obj->parent != 0)
       Py_DECREF(obj->parent);
   if(obj->owns)
       delete obj->data;
}

static PyObject *Plot_richcompare(PyObject *self, PyObject *other, int op);
PyObject *
PyPlot_getattr(PyObject *self, char *name)
{
    if(strcmp(name, "stateType") == 0)
        return Plot_GetStateType(self, NULL);
    if(strcmp(name, "NewlyCreated") == 0)
        return PyInt_FromLong(long(Plot::NewlyCreated));
    if(strcmp(name, "Pending") == 0)
        return PyInt_FromLong(long(Plot::Pending));
    if(strcmp(name, "Completed") == 0)
        return PyInt_FromLong(long(Plot::Completed));
    if(strcmp(name, "Error") == 0)
        return PyInt_FromLong(long(Plot::Error));

    if(strcmp(name, "plotType") == 0)
        return Plot_GetPlotType(self, NULL);
    if(strcmp(name, "plotName") == 0)
        return Plot_GetPlotName(self, NULL);
    if(strcmp(name, "activeFlag") == 0)
        return Plot_GetActiveFlag(self, NULL);
    if(strcmp(name, "hiddenFlag") == 0)
        return Plot_GetHiddenFlag(self, NULL);
    if(strcmp(name, "expandedFlag") == 0)
        return Plot_GetExpandedFlag(self, NULL);
    if(strcmp(name, "plotVar") == 0)
        return Plot_GetPlotVar(self, NULL);
    if(strcmp(name, "databaseName") == 0)
        return Plot_GetDatabaseName(self, NULL);
    if(strcmp(name, "operators") == 0)
        return Plot_GetOperators(self, NULL);
    if(strcmp(name, "operatorNames") == 0)
        return Plot_GetOperatorNames(self, NULL);
    if(strcmp(name, "activeOperator") == 0)
        return Plot_GetActiveOperator(self, NULL);
    if(strcmp(name, "id") == 0)
        return Plot_GetId(self, NULL);
    if(strcmp(name, "embeddedPlotId") == 0)
        return Plot_GetEmbeddedPlotId(self, NULL);
    if(strcmp(name, "beginFrame") == 0)
        return Plot_GetBeginFrame(self, NULL);
    if(strcmp(name, "endFrame") == 0)
        return Plot_GetEndFrame(self, NULL);
    if(strcmp(name, "keyframes") == 0)
        return Plot_GetKeyframes(self, NULL);
    if(strcmp(name, "numKeyframesPerOperator") == 0)
        return Plot_GetNumKeyframesPerOperator(self, NULL);
    if(strcmp(name, "operatorKeyframes") == 0)
        return Plot_GetOperatorKeyframes(self, NULL);
    if(strcmp(name, "databaseKeyframes") == 0)
        return Plot_GetDatabaseKeyframes(self, NULL);
    if(strcmp(name, "isFromSimulation") == 0)
        return Plot_GetIsFromSimulation(self, NULL);
    if(strcmp(name, "followsTime") == 0)
        return Plot_GetFollowsTime(self, NULL);
    if(strcmp(name, "description") == 0)
        return Plot_GetDescription(self, NULL);
    if(strcmp(name, "selection") == 0)
        return Plot_GetSelection(self, NULL);
    if(strcmp(name, "animatingFlag") == 0)
        return Plot_GetAnimatingFlag(self, NULL);


    // Add a __dict__ answer so that dir() works
    if (!strcmp(name, "__dict__"))
    {
        PyObject *result = PyDict_New();
        for (int i = 0; PyPlot_methods[i].ml_meth; i++)
            PyDict_SetItem(result,
                PyString_FromString(PyPlot_methods[i].ml_name),
                PyString_FromString(PyPlot_methods[i].ml_name));
        return result;
    }

    return Py_FindMethod(PyPlot_methods, self, name);
}

int
PyPlot_setattr(PyObject *self, char *name, PyObject *args)
{
    PyObject NULL_PY_OBJ;
    PyObject *obj = &NULL_PY_OBJ;

    if(strcmp(name, "stateType") == 0)
        obj = Plot_SetStateType(self, args);
    else if(strcmp(name, "plotType") == 0)
        obj = Plot_SetPlotType(self, args);
    else if(strcmp(name, "plotName") == 0)
        obj = Plot_SetPlotName(self, args);
    else if(strcmp(name, "activeFlag") == 0)
        obj = Plot_SetActiveFlag(self, args);
    else if(strcmp(name, "hiddenFlag") == 0)
        obj = Plot_SetHiddenFlag(self, args);
    else if(strcmp(name, "expandedFlag") == 0)
        obj = Plot_SetExpandedFlag(self, args);
    else if(strcmp(name, "plotVar") == 0)
        obj = Plot_SetPlotVar(self, args);
    else if(strcmp(name, "databaseName") == 0)
        obj = Plot_SetDatabaseName(self, args);
    else if(strcmp(name, "operators") == 0)
        obj = Plot_SetOperators(self, args);
    else if(strcmp(name, "operatorNames") == 0)
        obj = Plot_SetOperatorNames(self, args);
    else if(strcmp(name, "activeOperator") == 0)
        obj = Plot_SetActiveOperator(self, args);
    else if(strcmp(name, "id") == 0)
        obj = Plot_SetId(self, args);
    else if(strcmp(name, "embeddedPlotId") == 0)
        obj = Plot_SetEmbeddedPlotId(self, args);
    else if(strcmp(name, "beginFrame") == 0)
        obj = Plot_SetBeginFrame(self, args);
    else if(strcmp(name, "endFrame") == 0)
        obj = Plot_SetEndFrame(self, args);
    else if(strcmp(name, "keyframes") == 0)
        obj = Plot_SetKeyframes(self, args);
    else if(strcmp(name, "numKeyframesPerOperator") == 0)
        obj = Plot_SetNumKeyframesPerOperator(self, args);
    else if(strcmp(name, "operatorKeyframes") == 0)
        obj = Plot_SetOperatorKeyframes(self, args);
    else if(strcmp(name, "databaseKeyframes") == 0)
        obj = Plot_SetDatabaseKeyframes(self, args);
    else if(strcmp(name, "isFromSimulation") == 0)
        obj = Plot_SetIsFromSimulation(self, args);
    else if(strcmp(name, "followsTime") == 0)
        obj = Plot_SetFollowsTime(self, args);
    else if(strcmp(name, "description") == 0)
        obj = Plot_SetDescription(self, args);
    else if(strcmp(name, "selection") == 0)
        obj = Plot_SetSelection(self, args);
    else if(strcmp(name, "animatingFlag") == 0)
        obj = Plot_SetAnimatingFlag(self, args);

    if (obj != NULL && obj != &NULL_PY_OBJ)
        Py_DECREF(obj);

    if (obj == &NULL_PY_OBJ)
    {
        obj = NULL;
        PyErr_Format(PyExc_NameError, "name '%s' is not defined", name);
    }
    else if (obj == NULL && !PyErr_Occurred())
        PyErr_Format(PyExc_RuntimeError, "unknown problem with '%s'", name);

    return (obj != NULL) ? 0 : -1;
}

static int
Plot_print(PyObject *v, FILE *fp, int flags)
{
    PlotObject *obj = (PlotObject *)v;
    fprintf(fp, "%s", PyPlot_ToString(obj->data, "",false).c_str());
    return 0;
}

PyObject *
Plot_str(PyObject *v)
{
    PlotObject *obj = (PlotObject *)v;
    return PyString_FromString(PyPlot_ToString(obj->data,"", false).c_str());
}

//
// The doc string for the class.
//
#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 5)
static const char *Plot_Purpose = "This class is a plot element in a plot list.";
#else
static char *Plot_Purpose = "This class is a plot element in a plot list.";
#endif

//
// Python Type Struct Def Macro from Py2and3Support.h
//
//         VISIT_PY_TYPE_OBJ( VPY_TYPE,
//                            VPY_NAME,
//                            VPY_OBJECT,
//                            VPY_DEALLOC,
//                            VPY_PRINT,
//                            VPY_GETATTR,
//                            VPY_SETATTR,
//                            VPY_STR,
//                            VPY_PURPOSE,
//                            VPY_RICHCOMP,
//                            VPY_AS_NUMBER)

//
// The type description structure
//

VISIT_PY_TYPE_OBJ(PlotType,         \
                  "Plot",           \
                  PlotObject,       \
                  Plot_dealloc,     \
                  Plot_print,       \
                  PyPlot_getattr,   \
                  PyPlot_setattr,   \
                  Plot_str,         \
                  Plot_Purpose,     \
                  Plot_richcompare, \
                  0); /* as_number*/

//
// Helper function for comparing.
//
static PyObject *
Plot_richcompare(PyObject *self, PyObject *other, int op)
{
    // only compare against the same type 
    if ( Py_TYPE(self) != &PlotType
         || Py_TYPE(other) != &PlotType)
    {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    PyObject *res = NULL;
    Plot *a = ((PlotObject *)self)->data;
    Plot *b = ((PlotObject *)other)->data;

    switch (op)
    {
       case Py_EQ:
           res = (*a == *b) ? Py_True : Py_False;
           break;
       case Py_NE:
           res = (*a != *b) ? Py_True : Py_False;
           break;
       default:
           res = Py_NotImplemented;
           break;
    }

    Py_INCREF(res);
    return res;
}

//
// Helper functions for object allocation.
//

static Plot *defaultAtts = 0;
static Plot *currentAtts = 0;

static PyObject *
NewPlot(int useCurrent)
{
    PlotObject *newObject;
    newObject = PyObject_NEW(PlotObject, &PlotType);
    if(newObject == NULL)
        return NULL;
    if(useCurrent && currentAtts != 0)
        newObject->data = new Plot(*currentAtts);
    else if(defaultAtts != 0)
        newObject->data = new Plot(*defaultAtts);
    else
        newObject->data = new Plot;
    newObject->owns = true;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

static PyObject *
WrapPlot(const Plot *attr)
{
    PlotObject *newObject;
    newObject = PyObject_NEW(PlotObject, &PlotType);
    if(newObject == NULL)
        return NULL;
    newObject->data = (Plot *)attr;
    newObject->owns = false;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

///////////////////////////////////////////////////////////////////////////////
//
// Interface that is exposed to the VisIt module.
//
///////////////////////////////////////////////////////////////////////////////

PyObject *
Plot_new(PyObject *self, PyObject *args)
{
    int useCurrent = 0;
    if (!PyArg_ParseTuple(args, "i", &useCurrent))
    {
        if (!PyArg_ParseTuple(args, ""))
            return NULL;
        else
            PyErr_Clear();
    }

    return (PyObject *)NewPlot(useCurrent);
}

//
// Plugin method table. These methods are added to the visitmodule's methods.
//
static PyMethodDef PlotMethods[] = {
    {"Plot", Plot_new, METH_VARARGS},
    {NULL,      NULL}        /* Sentinel */
};

static Observer *PlotObserver = 0;

std::string
PyPlot_GetLogString()
{
    std::string s("Plot = Plot()\n");
    if(currentAtts != 0)
        s += PyPlot_ToString(currentAtts, "Plot.", true);
    return s;
}

static void
PyPlot_CallLogRoutine(Subject *subj, void *data)
{
    typedef void (*logCallback)(const std::string &);
    logCallback cb = (logCallback)data;

    if(cb != 0)
    {
        std::string s("Plot = Plot()\n");
        s += PyPlot_ToString(currentAtts, "Plot.", true);
        cb(s);
    }
}

void
PyPlot_StartUp(Plot *subj, void *data)
{
    if(subj == 0)
        return;

    currentAtts = subj;
    PyPlot_SetDefaults(subj);

    //
    // Create the observer that will be notified when the attributes change.
    //
    if(PlotObserver == 0)
    {
        PlotObserver = new ObserverToCallback(subj,
            PyPlot_CallLogRoutine, (void *)data);
    }

}

void
PyPlot_CloseDown()
{
    delete defaultAtts;
    defaultAtts = 0;
    delete PlotObserver;
    PlotObserver = 0;
}

PyMethodDef *
PyPlot_GetMethodTable(int *nMethods)
{
    *nMethods = 1;
    return PlotMethods;
}

bool
PyPlot_Check(PyObject *obj)
{
    return (obj->ob_type == &PlotType);
}

Plot *
PyPlot_FromPyObject(PyObject *obj)
{
    PlotObject *obj2 = (PlotObject *)obj;
    return obj2->data;
}

PyObject *
PyPlot_New()
{
    return NewPlot(0);
}

PyObject *
PyPlot_Wrap(const Plot *attr)
{
    return WrapPlot(attr);
}

void
PyPlot_SetParent(PyObject *obj, PyObject *parent)
{
    PlotObject *obj2 = (PlotObject *)obj;
    obj2->parent = parent;
}

void
PyPlot_SetDefaults(const Plot *atts)
{
    if(defaultAtts)
        delete defaultAtts;

    defaultAtts = new Plot(*atts);
}

